package com.fcat.base.smartapi.lib;

import java.math.BigInteger;

public class SimpleManToken extends BaseToken {
    // Token: 0x04000031 RID: 49
    public BigInteger Control;

    // Token: 0x04000032 RID: 50
    public byte Mfrcode;

    public SimpleManToken() {
        super.SetWorkType(WorkType.STA);
        this.TClassNum = 1;
        this.TSubClassNum = 0;
    }

    public SimpleManToken(BigInteger control) {
        super.SetWorkType(WorkType.STA);
        this.TClassNum = 1;
        this.TSubClassNum = 0;
        this.Control = control;
        this.Mfrcode = 0;
        this.EToByteTokens();
        this.MakeToken(this.ByteTokens);
    }

    public SimpleManToken(byte subClass, BigInteger control, boolean mode) {
        super.SetWorkType(WorkType.STA);
        this.testMode = mode;
        this.TClassNum = 1;
        this.TSubClassNum = subClass;
        this.Control = control;
        this.Mfrcode = 0;
        this.EToByteTokens();
        this.MakeToken(this.ByteTokens);
    }

    public SimpleManToken(byte subClass, BigInteger control, byte mfrcode) {
        this.TClassNum = 1;
        this.TSubClassNum = subClass;
        this.Control = control;
        this.Mfrcode = mfrcode;
        this.EToByteTokens();
        this.MakeToken(this.ByteTokens);
    }


    @Override
    protected void EToByteTokens() {
        this.ByteTokens[0] = this.TClassNum;
        //ORIGINAL LINE: this.ByteTokens[1] = (byte)((ulong)((uint)(this.Control >> 32)) + (ulong)((long)((long)this.TSubClassNum << 4)));
        this.ByteTokens[1] = (byte)((long)((int)((this.Control.longValue() & 0xFFFFFFFFFFFFFFFFL) >> 32)) + (long)((long)((long)this.TSubClassNum << 4)));
        //ORIGINAL LINE: this.ByteTokens[2] = (byte)(this.Control >> 24 & 255UL);
        this.ByteTokens[2] = (byte)((this.Control.longValue() & 0xFFFFFFFFFFFFFFFFL) >> 24 & 255);
        //ORIGINAL LINE: this.ByteTokens[3] = (byte)(this.Control >> 16 & 255UL);
        this.ByteTokens[3] = (byte)((this.Control.longValue() & 0xFFFFFFFFFFFFFFFFL) >> 16 & 255);
        //ORIGINAL LINE: this.ByteTokens[4] = (byte)(this.Control >> 8 & 255UL);
        this.ByteTokens[4] = (byte)((this.Control.longValue() & 0xFFFFFFFFFFFFFFFFL) >> 8 & 255);
        //ORIGINAL LINE: this.ByteTokens[5] = (byte)(this.Control & 255UL);
        this.ByteTokens[5] = (byte)(this.Control.longValue() & 255);
        //ORIGINAL LINE: this.ByteTokens[6] = (this.Mfrcode & byte.MaxValue);
        this.ByteTokens[6] = (byte) (this.Mfrcode & 0xFF);
    }

    //ORIGINAL LINE: public string MakeToken(byte[] source)
    public final String MakeToken(byte[] source) {
        if (source.length < 7) {
            this.xErr = 40;
            return "";
        }
        this.TCRC = super.CheckCRC(source);
        //ORIGINAL LINE: byte[] infoTmp = new byte[8];
        byte[] infoTmp = new byte[8];
        //ORIGINAL LINE: infoTmp[0] = (byte)(this.TCRC & 255);
        infoTmp[0] = (byte)(this.TCRC & 255);
        //ORIGINAL LINE: infoTmp[1] = (byte)(this.TCRC >> 8 & 255);
        infoTmp[1] = (byte)(this.TCRC >> 8 & 255);
        for (int i = 0; i < 6; i++)
        {
            infoTmp[8 - (i + 1)] = source[i + 1];
        }
        this.StrToken = "00000000000000000000";
        this.StrToken += super.HexToStrDec(infoTmp, this.TClassNum);
        this.StrToken = this.StrToken.substring(this.StrToken.length() - 20, this.StrToken.length() - 20 + 20);
        return this.StrToken;
    }

    public final void MakeToken()
    {
        this.xErr = -1;
        this.EToByteTokens();
        this.MakeToken(this.ByteTokens);
    }

    //ORIGINAL LINE: internal void MakeToken(byte subClass, ulong control, byte mcode)
    public final void MakeToken(byte subClass, BigInteger control, byte mcode)
    {
        this.xErr = -1;
        this.Mfrcode = mcode;
        this.TClassNum = 1;
        this.TSubClassNum = subClass;
        this.Control = control;
        this.MakeToken();
    }

}
